package tech.edwardvan.designpattern.pattern.creational.factorymethod;


import lombok.extern.slf4j.Slf4j;

/**
 * 工厂方法模式
 * <p>
 * 工厂方法模式是弥补简单工厂模式中产品单一,扩展难的缺点
 *
 * @author EdwardVan
 */
@Slf4j
public class FactoryMethodDemo {

    public static void main(String[] args) {
        GPU gpu = new MsiGPUFactory().produce();
        gpu.output();
        gpu = new AsusGPUFactory().produce();
        gpu.output();
    }


    /**
     * GPU工厂接口
     */
    private interface GPUFactory {
        GPU produce();
    }

    private static class MsiGPUFactory implements GPUFactory {

        @Override
        public GPU produce() {
            //复杂的创建过程
            return new MsiGPU();
        }
    }

    private static class ColorfulGPUFactory implements GPUFactory {

        @Override
        public GPU produce() {
            //复杂的创建过程
            return new ColorfulGPU();
        }
    }

    /**
     * 方便拓展
     */
    private static class AsusGPUFactory implements GPUFactory {

        @Override
        public GPU produce() {
            //复杂的创建过程
            return new AsusGPU();
        }
    }


    private interface GPU {
        void output();
    }

    private static class MsiGPU implements GPU {

        @Override
        public void output() {
            log.info("微星显卡输出");
        }
    }

    private static class ColorfulGPU implements GPU {

        @Override
        public void output() {
            log.info("七彩虹显卡输出");
        }
    }

    private static class AsusGPU implements GPU {

        @Override
        public void output() {
            log.info("华硕显卡输出");
        }
    }
}
